<?php
defined('IN_MAIN') or exit('Invalid Access!');

function format_xml($data, $format_xml_header=true){
//format the data into xml format, and set the header to 'text/xml' by default
global $vars;
$sep="<br />\n";
if(count($data)){
 foreach($data as $field=>$value){
  $sep_value=(strstr($value, $sep)? explode($sep, $value) : array($value));
  for($i=0;$i<count($sep_value);$i++){
   $xml_data.=($i==count($sep_value)-1 && !strlen($sep_value[$i])? "" : "<$field>".nhtmlentities($sep_value[$i])."</$field>\n");
  }
 }
}

$xml=$xml_data;

if($format_xml_header){
$xml="<?xml version=\"1.0\" encoding='$vars[charset]'?>
<response>
$xml_data
</response>";
 header("Content-type: text/xml");
 header("Cache-Control: no-cache");
}

return $xml;
}
?>